package com.pulook.daikuan.controller;

import java.util.List;

import javax.inject.Inject;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.pulook.daikuan.dao.HuankuanMapper;
import com.pulook.daikuan.dao.SessionUtil;
import com.pulook.daikuan.dao.ShenqingMapper;
import com.pulook.daikuan.model.Huankuan;
import com.pulook.daikuan.model.Shenqing;

@Controller
public class Yonghuye {

	@Inject
	ShenqingMapper s;
	public Shenqing s1;
	@Inject
	HuankuanMapper h;
	public Huankuan h1;
	
	/***-----用户
	 *  用户主页
	 */
	@RequestMapping("/zhuye")
	public String yhzy(Model m){
		
		String shenqingyonghu = (String)SessionUtil.getAttributeFromSessionByKey("yonghuming");
		Shenqing sq = new Shenqing();
		sq.setShenqingyonghu(shenqingyonghu);
		int num = s.getByConditionForNum(sq);
		sq.setStart(0);
		sq.setEnd(num);
		List<Shenqing> desc = s.getShenqingByConditionDesc(sq);
		m.addAttribute("desc", desc);
		
		return "zhuye";
	}
	
	/***
	 * 用户申请贷款页
	 */
	@RequestMapping("/daikuanye")
	public String dky(){
		
		return "daikuanye";
	}
	
	/***
	 * 贷款表单处理
	 */
	@RequestMapping("/dkbiaodan")
	public String dkbd(Shenqing sq){
		
		sq.setZhuangtai("未审核");
		s.insert(sq);
		
		return "forward:zhuye";
	}
	
	/***
	 * 还款页面浏览页
	 */
	@RequestMapping("/huankuanye")
	public String hky(Model m){
		
		Huankuan hk1 = new Huankuan();
		hk1.setKehuming((String)SessionUtil.getAttributeFromSessionByKey("xingming"));
		hk1.setZhuangtai("进行中");
		int num = h.getByConditionForNum(hk1);
		hk1.setStart(0);
		hk1.setEnd(num);
		List<Huankuan> desc = h.getHuankuanByConditionDesc(hk1);
		
		Huankuan hk11 = new Huankuan();
		hk11.setKehuming((String)SessionUtil.getAttributeFromSessionByKey("xingming"));
		hk11.setZhuangtai("完结");
		int num1 = h.getByConditionForNum(hk11);
		hk11.setStart(0);
		hk11.setEnd(num1);
		List<Huankuan> desc1 = h.getHuankuanByConditionDesc(hk11);
		
		m.addAttribute("desc", desc);
		m.addAttribute("desc1", desc1);
		
		return "huankuanye";
	}
}
